<?php
class adv extends common{
	
	function __construct(){	
		$pagec = new page($_GET['page']);
		parent::__construct($pagec);
	}	
	private $table_adv = 'adv';						//广告表
	private $table_adv_position = 'adv_position';	//广告位置表


	/**
	 * 广告列表
	 * @author	jsy
	 * @param	string	$where  
	 * @param	string	$key 
	 * @param	int	$is_page  
	 * @return 	array
	 */

	function adv_list($where='',$key="a.*,p.position",$is_page=false){
		$sql = $this->table_adv." a LEFT JOIN ".$this->table_adv_position." p ON a.position_id=p.id WHERE 1=1 ".$where." order by a.position_id ,a.sort desc" ;
		if($is_page){
			$sql_num = $sql;
		}else{
			$sql_num = "";
		}
		$res = $this->getList($sql,$sql_num,$key);
		return $res ;
	}


	/**
	 * 广告列表
	 * @author	jsy
	 * @param	string	$where  
	 * @param	string	$key 
	 * @param	int	$is_page  
	 * @return 	array
	 */

	function adv_position_list($where='',$key="p.*",$is_page=false){
		$sql =$this->table_adv_position." p  WHERE 1=1 ".$where." order by p.id " ;
		if($is_page){
			$sql_num = $sql;
		}else{
			$sql_num = "";
		}
		$res = $this->getList($sql,$sql_num,$key);
		return $res ;
	}




	/**
	 * 广告添加
	 * @author	jsy	
	 * @param	array	$arr 		 //数组
	 * @return 	bool
	 */
	function adv_add($arr){
		if( !empty($arr)){
			$res = $this->insert($this->table_adv,$arr);	
			$id = $this->insert_id();

			$res = $this->update($this->table_adv,array('sort'=>$id),'id='.$id);
		}
		return $res;
	}

	/**
	 * 广告修改
	 * @author	jsy	
	 * @param	int		$id 		 
	 * @param	array	$arr 		 //数组
	 * @return 	bool
	 */
	function adv_update($id,$arr){
		if( !empty($arr)){
			$res = $this->update($this->table_adv,$arr,'id='.$id);
		}
		return $res;
	}

	/**
	 * 广告详情
	 * @author	jsy	
	 * @param	int		$id 		 
	 * @return 	array
	 */
	function adv_info($id){
		$res = $this->getInfo($this->table_adv,$id);
		return $res;
	}



}
?>